package com.chaosj.skill.guava.basic

import com.google.common.base.CaseFormat

/**
 * @Description:
 * @author: caoyangjie
 * @date: 2019年11月2019/11/18日 15:11
 * @Copyright: © 赢时胜
 */
class GuavaCaseFormater {
    static void main(args){
        // 连接符 - 转换为 下划线 _      hello-world ->  hello_world
        println(hyphenToUnder("hello-world"))
        // 下划线 _ 转换为 连接符 -  hello_world     ->  hello-world
        println(underToHyphen("hello_world"))
        // 连接符 - 转换为 首字母小写,其他连接符后跟字母大写  hello-world -> helloWorld
        println(hyphenToCamel("hello-world"))
        // 连接符 - 转换为 全大写   hello-world  ->  HelloWorld
        println(hyphenToUCamel("hello-world"))

        println(underToCamel("PUBLISHER_CODE"))
        println(underToUCamel("PUBLISHER_CODE"))
    }

    static String hyphenToUnder(String value){
        CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_UNDERSCORE,value)
    }

    static String underToHyphen(String value){
        CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN,value)
    }

    static String underToCamel(String value){
        CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,value)
    }

    static String hyphenToCamel(String value){
        CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,value)
    }

    static String hyphenToUCamel(String value){
        CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL,value)
    }

    static String underToUCamel(String value){
        value = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN,value)
        CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL,value)
    }
}
